package chapter1.listSet.task;

import java.util.*;

/*
3：在Set中放入若干随机的整数，比如10个，然后删除其中的偶数。最后输出这个Set
 */
public class Task3 {
    public static void main(String[] args) {
        Random random = new Random();
        Iterator<Integer> iterator;
        Set<Integer> set = new HashSet<>();
        int a;
        while (set.size() < 10) {
            set.add(random.nextInt());
        }
        System.out.println("Set中的元素为：");
        for (Integer b : set)
            System.out.print(b + "  ");
        System.out.println();
        iterator = set.iterator();
        while (iterator.hasNext()) {
            if (((a = iterator.next()) % 2) == 0)
                iterator.remove();
        }
        System.out.println("删除偶数后，Set中的元素为：");
        for (Integer b : set)
            System.out.print(b + "  ");
    }
}
